 import Vue from 'vue'
 import VueRouter from 'vue-router'
 import Home from '../pages/Home'
 import About from '../pages/About'

 Vue.use(VueRouter)
 //对VueRouter原型上push和replace进行增强，目的是：解决编程式重复跳转报错问题

 //第一步：缓存原始的push和replace
 const originalPush = VueRouter.prototype.push
 const originalReplace = VueRouter.prototype.replace

 //第二步：增强push
 VueRouter.prototype.push = function(location,okCallback,errCallback){
	//若程序员使用push的时候，没有传递成功、失败的回调，那就靠catch
	if(okCallback === undefined && errCallback === undefined){
		return originalPush.call(this,location).catch(()=>{})
	}else{
		//若程序员使用push的时候，传递了成功、失败的回调，那就用
		return originalPush.call(this,location,okCallback,errCallback)
	}
 }
 //第三步：增强replace
 VueRouter.prototype.replace = function(location,okCallback,errCallback){
	//若程序员使用push的时候，没有传递成功、失败的回调，那就靠catch
	if(okCallback === undefined && errCallback === undefined){
		return originalReplace.call(this,location).catch(()=>{})
	}else{
		//若程序员使用push的时候，传递了成功、失败的回调，那就用
		return originalReplace.call(this,location,okCallback,errCallback)
	}
 }

//创建一个路由器
let router = new VueRouter({
	// mode:'history',
	routes:[
		{
			name:'guanyu',
			path:'/about',
			component:About
		},
		{
			name:'zhuye',
			path:'/home',
			component:Home,
		}
	]
 })

 //暴露路由器
 export default router
